package service_blog_mirchen_com

import (
	"github.com/jinzhu/gorm"
	"gen-go/BlogServices"
)

//service结构
type LinkServiceHandler struct {
	orm *gorm.DB
}

//tag
type Links struct {
	Id       int64  `gorm:"primary_key"`
	LinkName string
	LinkUrl  string
	Sort     int64
}

func NewLinkServiceHandler(getOrm *gorm.DB) *LinkServiceHandler {
	return &LinkServiceHandler{orm:getOrm}
}

func (lsh *LinkServiceHandler) GetAllLinks() ([]*BlogServices.Link, error) {
	links := []Links{}
	retLinks := []*BlogServices.Link{}
	err := lsh.orm.Find(&links).Error
	if err != nil {
		return retLinks, err
	}
	length := len(links)
	if length > 0 {
		for _, v := range links {
			retLinks = append(retLinks, &BlogServices.Link{
				ID:v.Id,
				LinkName:v.LinkName,
				LinkUrl:v.LinkUrl,
			})
		}
	}
	return retLinks, nil
}
